/*
 * Copyright (c) Jan Šlahora (${USER}) - 2012.
 * Created in IntelliJ IDEA 10.5
 */

package statistics;

import GUIComponents.Tabulka;
import MW.MW;
import text.DejCetnosti;

import java.util.ArrayList;
import java.util.HashMap;

/*
*   File VelikostVyberu
*   in package statistics
*   was created by slaha
*   on 21.3.12 at 23:35.
*
*/
public class VelikostVyberu extends Samohlasky implements Runnable {

  final static double PRESNOST = 0.005;
  DejCetnosti.CetnostZnaku cZ;
  double N;

  public VelikostVyberu(DejCetnosti.CetnostZnaku cZ) {
    this.N = 1;
    if (cZ != null) {
      this.cZ = cZ;
      run();
    }
  }

  @Override
  public void run() {
    Tabulka t = new Tabulka(null, cZ.getHm());
    HashMap<Character, Double> pravdepodobnosti = dejPravdepodobnosti(t.getData());

    double zlomek = 1d / (pravdepodobnosti.size() - 1);
    double suma = 0;
    for (double d : pravdepodobnosti.values()) {
      suma += Math.log(d);
    }
    double minus = 2 * Math.log(PRESNOST);
    double vzorec = zlomek * suma - minus;

    N = Math.exp(vzorec);
  }

  public double getN() {
    return N;
  }
}
